home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 426-450 / disk_429 / uedit-stuff / indent < prev    next >
Text File  |  1992-05-06  |  18KB  |  474 lines

  1. ++++++++++++++++++++++++++++
  2. *** Indent-related Uedit functions by Paul Kienitz
  3. ++++++++++++++++++++++++++++
  4.  
  5. Move cursor to first non-whitespace on current line
  6. .. Ue 2.4 version: <ctl-[:
  7.         if (not is(curfile, sline)) movecursor(curfile, sline)
  8.         label (2)
  9.             if (not is(curfile, space))
  10.                 if (not is(curfile, 9))  ..tab
  11.                     goto label (1)
  12.             movecursor(curfile, echar)
  13.             goto label (2)
  14.         label (1)
  15.         loctocol(curfile, n50, atcursor)
  16. >   reports column in n50
  17.  
  18. Move cursor to first non-whitespace on current line
  19. <ctl-[: if (not is(curfile, sline))
  20.             movecursor(curfile, sline)
  21.         while (is(curfile, space) | is(curfile, 9))
  22.             movecursor(curfile, echar)
  23.         loctocol(curfile, n50, atcursor)
  24. >  reports column in n50
  25.  
  26. Indent with alt-] if cursor in leading whitespace, else insert tab
  27. <normal-tab:    equateloc(curfile, locA, atcursor)
  28.                 label (37)
  29.                     if (is(curfile, sline))
  30.                         goto label (21)
  31.                     else movecursor(curfile, schar)
  32.                     if (not is(curfile, whitespace))
  33.                         goto label (96)
  34.                     goto label (37)
  35.                 label (96)      .. we are in the line's text, just insert tab
  36.                     equateloc(curfile, atcursor, locA)
  37.                     typechar(9)
  38.                     return
  39.                 label (21)      .. we are in the leading indent, run alt-]
  40.                     runkey(alt-])
  41. >
  42.  
  43. When using this version of normal-tab, I like to define shft-tab to simply
  44. insert two tab characters, just cause that might take four presses of normal-
  45. tab when using this ...  just <shft-tab: typechar(9) typechar(9) >
  46.  
  47. Un-indent with alt-[ if in leading whitespace, else delete last char
  48. ..<normal-bs:   if (is(curfile, sline)) {
  49.                     if (eqloc(curfile, atcursor, spage))
  50.                         vscroll(atcursor)               .. bug workaround
  51.                     if (movecursor(curfile, schar))
  52.                         clearchar(curfile)
  53.                     return
  54.                 }
  55.                 equateloc(curfile, locA, atcursor)
  56.                 while (movecursor(curfile, schar)) {
  57.                     if (not is(curfile, whitespace)) {     .. we're in mid-line
  58.                         movecursor(curfile, locA)
  59.                         movecursor(curfile, schar)
  60.                         clearchar(curfile)
  61.                         return
  62.                     }
  63.                     if (is(curfile, sline)) {   .. we are in the leading indent
  64.                         runkey(alt-[)
  65.                         return
  66.                     }
  67.                 }
  68. >  Grrrr.   This is too slow to use, unless you use the UEK version.
  69.    And it should single-backspace sometimes?
  70.  
  71. Set indent size for alt-] and alt-[
  72. <shftAlt-]:     putmsg(
  73. "How many spaces should alt-] indent? (1 to 9, or 0 means 10)")
  74.                 getchar(n54)
  75.                 sub(n54, n54, "0")
  76.                 if (gtnum(n54, 9)) goto label (1)
  77.                 if (gtnum(0, n54)) goto label (1)
  78.                 if (eqnum(0, n54)) equatenum(n54, 10)           .. 0 means 10
  79.  .. instead:     putmsg("How many lines should alt-] indent?")
  80.  ..              if (not inputNum(n54)) goto label (1)
  81.                 equatenum(n44, n54)
  82.                 putmsg(" ")
  83.                 return
  84.                     label (1)
  85.                     putmsg("Not a number")
  86. >
  87.  
  88. Un-indent line according to indentation of lines above
  89. <lamiga-[:
  90.         equateloc(curfile, locA, atcursor)
  91.         runkey(ctl-[)
  92.         ..if (eqnum(n50, 1)) { equateloc(curfile, atcursor, locA)   return }
  93.         equatenum(n51, n50)
  94.         do (n52, 1, 6) {      .. <- set limit of how many lines to look at here
  95.             if (not movecursor(curfile, upline))
  96.                 goto label (57)
  97.             runkey(ctl-[)            .. find indent level of near previous line
  98.             if (gtnum(n51, n50))          .. aha, this is less indented than us
  99.             if (gtnum(n50, 1)) {               .. but not completely unindented
  100.                 equatenum(n54, n50)                    .. so this is the indent
  101.                 goto label (69)                          .. to use for our line
  102.             }
  103.         }
  104.     label (57)                  ..       vvv  default value @@
  105.         if (genum(0, n44)) equatenum(n44, 4)    .. no guidance from above
  106.         if (gtnum(n51, n44)) sub(n54, n51, n44) .. lines, so mimic alt-[ 
  107.         else equatenum(n54, 1)
  108.     label (69)
  109.         movecursor(curfile, locA)       .. get cursor back to original line
  110.         runkey(virtual-[)
  111. >
  112. **** THIS NEEDS something to make normal-tab and normal-bs work primitively
  113. in the case where indentation matches the tab table (e.g. 8 spaces 0 lines).
  114.  
  115. Indent line to align after next whitespace in line above
  116. <lamiga-]:      equateloc(curfile, locA, atcursor)
  117.                 runkey(ctl-[)
  118.                 equatenum(n51, n50)
  119.                 if (not movecursor(curfile, upline))
  120.                     goto label (42)
  121.                 while (is(curfile, blankline))
  122.                     if (not movecursor(curfile, upline))
  123.                         goto label (42)
  124.                 runkey(ctl-[)
  125.                 while (genum(n51, n50) & not is(curfile, eline)) {
  126.                     while (not is(curfile, whitespace))
  127.                         movecursor(curfile, echar)
  128.                     while (not is(curfile, eline) & is(curfile, whitespace))
  129.                         movecursor(curfile, echar)
  130.                     loctocol(curfile, n50, atcursor)
  131.                 }
  132.                 movecursor(curfile, locA)
  133.                 equatenum(n54, n50)
  134.                 runkey(virtual-[)
  135.                 return
  136.                     label (42)
  137.                     movecursor(curfile, locA)
  138.                     returnFalse
  139. >
  140.  
  141.  
  142. Un-indent cursor line by one space
  143. <altctl-[:      equatenum(n1, n44)
  144.                 equatenum(n44, 1)
  145.                 runkey(alt-[)
  146.                 equatenum(n44, n1)
  147. >
  148.  
  149. Un-indent this line one step, where step size is set by shftAlt-]
  150. <alt-[: equateloc(curfile, locA, atcursor)
  151.         runkey(ctl-[)
  152.         if (genum(0, n44)) equatenum(n44, 4)            .. default @@
  153.         if (gtnum(n50, n44)) sub(n54, n50, n44)
  154.         else equatenum(n54, 1)
  155.         runkey(virtual-[)
  156. >
  157.  
  158. Indent this line one step, where step size is set by shftAlt-]
  159. <alt-]: equateloc(curfile, locA, atcursor)
  160.         runkey(ctl-[)
  161.         if (genum(0, n44)) equatenum(n44, 4)            .. default @@
  162.         add(n54, n50, n44)
  163.         runkey(virtual-[)
  164. >
  165.  
  166. Indent cursor line by one space
  167. <altctl-]:      equatenum(n1, n44)
  168.                 equatenum(n44, 1)
  169.                 runkey(alt-])
  170.                 equatenum(n44, n1)
  171. >
  172.  
  173. Indent cursor line to column specified in n54, leave cursor at locA
  174. <virtual-[:     if (not is(curfile, sline)) movecursor(curfile, sline)
  175.                 getlocal(curfile, n52, leftmargin)
  176.                 setlocal(curfile, leftmargin, n54)
  177. .... God dammit, the manual says that nonzero leftmargin causes autoindent
  178. .... to be ignored.  But in my version autoindent false causes leftmargin
  179. .... to be ignored!  Grrr:
  180.                 if (not getflag(curfile, autoindent)) {
  181.                     add(n52, n52, 100000)
  182.                     flipflag(curfile, autoindent)
  183.                 }
  184.                 typechar(eline)         .. cause indent to leftmargin (n54)
  185.                 movecursor(curfile, upline)
  186.                 clearchar(curfile)
  187.                 if (genum(n52, 100000)) {
  188.                     sub(n52, n52, 100000)
  189.                     flipflag(curfile, autoindent)
  190.                 }
  191.                 setlocal(curfile, leftmargin, n52)      .. restore old margin
  192. .. SUPER BOGUS BUG WORKAROUND:
  193.                 if (getflag(curfile, mapchars)) {
  194.                     flipflag(curfile, mapchars)
  195.                     typechar(0)                 .. snaps it back to reality!
  196.                     flipflag(curfile, mapchars)
  197.                 } else
  198.                     typechar(0)
  199.                 movecursor(curfile, locA)
  200.                 if (is(curfile, sline)) runkey(ctl-[)
  201. >  This is kinda slow, but I don't see any better way -- UEK version is faster
  202.  
  203. Make C brackets { } with indent (set indent size with SA-])
  204. <shftalt-[:     if (movecursor(curfile, schar)) {
  205.                     if (not is(curfile, whitespace)) {
  206.                         movecursor(curfile, echar)
  207.                         insertchar(curfile, " ")
  208.                     } else movecursor(curfile, echar)
  209.                 }
  210.                 insertchar(curfile, "{")
  211.                 typechar(eline)
  212.                 if (not is(curfile, eline)) movecursor(curfile, eline)
  213.                 typechar(eline)
  214.                 insertchar(curfile, "}")
  215.                 if (eqloc(curfile, atcursor, efile)) {          .. new feech
  216.                     insertchar(curfile, eline)
  217.                     movecursor(curfile, schar)
  218.                 }
  219.                 movecursor(curfile, upline)
  220.                 runkey(alt-])
  221.                 if (not is(curfile, eline)) movecursor(curfile, eline)
  222. >  ....could use something to undo this if you hit it by accident
  223.  
  224. Un-indent the hilite region one step (set step size with SA-])
  225. <alt-l: if (geloc(curfile, shilite, ehilite)) returnfalse
  226.         moveCursor(curFile,sHilite)
  227.         movecursor(curfile, echar)      .. don't do line that ends with shilite
  228.         if (not is(curFile,sLine)) moveCursor(curFile,sLine)
  229.         while (gtloc(curfile, ehilite, atcursor)) {     .. don't do line that
  230.             runkey(alt-[)                               ..   starts with ehilite
  231.             if (not movecursor(curfile, downline))
  232.                 equateloc(curfile, atcursor, ehilite)   .. cheap escape hatch
  233.         }
  234. >
  235.  
  236. Un-indent the hilite region by one space
  237. <altctl-l:      equatenum(n1, n44)
  238.                 equatenum(n44, 1)
  239.                 runkey(alt-l)
  240.                 equatenum(n44, n1)
  241. >
  242.  
  243. Indent the hilite region one step (set step size with SA-])
  244. <alt-r: if (geloc(curfile, shilite, ehilite)) returnfalse
  245.         moveCursor(curFile,sHilite)
  246.         movecursor(curfile, echar)      .. don't do line that ends with shilite
  247.         if (not is(curFile,sLine)) moveCursor(curFile,sLine)
  248.         while (gtloc(curfile, ehilite, atcursor)) {     .. don't do line that
  249.             runkey(alt-])                               ..   starts with ehilite
  250.             if (not is(curFile,sLine)) moveCursor(curFile,sLine)
  251.             if (not movecursor(curfile, downline))
  252.                 equateloc(curfile, atcursor, ehilite)   .. cheap escape hatch
  253.         }
  254. >
  255.  
  256. Indent the hilite region by one space
  257. <altctl-r:      equatenum(n1, n44)
  258.                 equatenum(n44, 1)
  259.                 runkey(alt-r)
  260.                 equatenum(n44, n1)
  261. >
  262.  
  263. Ask how many spaces to indent the hilite region
  264. <shftaltctl-r:  putmsg(
  265. "Indent hilite region how many spaces?  (negative for un-indent)")
  266.                 equatenum(n1, n44)
  267.                 equatenum(n44, 0)
  268.                 if (inputnum(n44))
  269.                     if (gtnum(n44, 0))
  270.                         runkey(alt-r)
  271.                     else if (gtnum(0, n44)) {
  272.                         sub(n44, 0, n44)
  273.                         runkey(alt-l)
  274.                     } else
  275.                         putmsg("Invalid number")
  276.                 equatenum(n44, n1)
  277. >
  278.  
  279. +++++++++++++++++
  280. *** miscellaneous
  281.  
  282. Umlaut next vowel or insert one of these: © ½ ¼ ¡ ¿ « » ß × ÷ ± ° Ñ ñ
  283. <alt-/: putmsg("c=© 2=½ 4=¼ 1=¡ q=¿ ,=« .=» b=ß x=× v=÷ p=± d=° n=ñ vöwël=ümläüt")
  284.         getchar(n54)
  285.         putmsg(" ")
  286.         freebuf(buf54)
  287.         insertrgn(buf54, sfile,    .. array for looking up conversions:
  288. " !\"#$%'()*+«-»/0¡½3¼56789:;<=>?@ÄBCDËFGHÏJKLMÑÖPQRSTÜVWXYZ[\\]^_`äß©°ëfghïjklmñö±¿rstü÷w×ÿz{|}~ ", all)  .. "
  289.         sub(n54, n54, 32)
  290.         indextoloc(buf54, atcursor, n54)
  291.         copychar(buf54, n53)
  292.         typechar(n53)
  293. >
  294. We could use a Spanish version with accents instead of umlauts
  295.  
  296. Go to start of hilite
  297. <shft-kp1:      movecursor(curfile, shilite)  >
  298.  
  299. Go to end of hilite
  300. <shft-kp3:      movecursor(curfile, ehilite)  >
  301.  
  302. Go to start of invert
  303. <shftctl-kp1:   movecursor(curfile, sinvert)  >
  304.  
  305. Go to end of invert
  306. <shftctl-kp3:   movecursor(curfile, einvert)  >
  307.  
  308. Reset color permutation to 2103 if you hit alt-help by mistake.
  309. <lamiga-help:   setlocal(curfile, color, 0x93) >
  310.  
  311. For programmers:  Toggle number under cursor between hex/decimal
  312. <ctl-x: movecursor(curfile, eword)
  313.         movecursor(curfile, schar)
  314.         equatenum(n54, 0)
  315.         copychar(curfile, n53)
  316.         if (eqnum(n53, "l")) equatenum(n53, "L")
  317.         if (eqnum(n53, "L")) {
  318.             insertchar(curfile, " ")
  319.             movecursor(curfile, schar)
  320.             equatenum(n54, 1)
  321.         }
  322.         if (not is(curfile, sword)) movecursor(curfile, sword)
  323.         if (hexDecimal(curFile)) {
  324.             movecursor(curfile, eword)
  325.             movecursor(curfile, schar)                  .. compensate
  326.             if (is(curfile, "X")) clearchar(curfile)    .. for bug
  327.             else movecursor(curfile, echar)
  328.         } else movecursor(curfile, eword)
  329.         if (eqnum(n54, 1))  {
  330.             clearchar(curfile)
  331.             movecursor(curfile, echar)
  332.         }
  333. > it's way newnimproved
  334.  
  335. Convert whole word under the cursor to all lower case
  336. <ctl-l: movecursor(curfile, eword)
  337.         movecursor(curfile, sword)
  338.         while (not is(curfile, eword)) {
  339.             tolower(curfile)
  340.             movecursor(curfile, echar)
  341.         }
  342. >
  343.  
  344. Convert whole word under the cursor to all upper case
  345. <ctl-u: movecursor(curfile, eword)
  346.         movecursor(curfile, sword)
  347.         while (not is(curfile, eword)) {
  348.             toupper(curfile)
  349.             movecursor(curfile, echar)
  350.         }
  351. >
  352.  
  353. Convert this/next letter to uppercase, and rest of word to lowercase
  354. <ctl-c: while (not is(curfile, alpha)) movecursor(curfile, echar)
  355.         toupper(curfile)
  356.         movecursor(curfile, echar)
  357.         if (is(curfile, uppercase))
  358.             while (not is(curfile, eword)) {
  359.                 tolower(curfile)
  360.                 movecursor(curfile, echar)
  361.             }
  362.         else if (not is(curfile, eword)) movecursor(curfile, eword)
  363. >  leaves rest of word alone unless letter after first is uppercase
  364.  
  365. Transpose characters
  366. <alt-t: copychar(curfile, n53)
  367.         movecursor(curfile, schar)
  368.         copychar(curfile, n54)
  369.         swapchar(curfile, n53)
  370.         movecursor(curfile, echar)
  371.         swapchar(curfile, n54)
  372.         movecursor(curfile, echar)
  373. >
  374. Let's try for transpose words someday?
  375.  
  376. Record recent inputs in n10..n18
  377. ..<prekey: if (eqnum(macronum, normal-buttondown)) return  .. forget mouseclicks
  378.          if (eqnum(macronum, normal-buttonup)) return    .. ditto
  379.          .. if (not eqnum(inputchar, 0)) return  .. optionally forget text
  380.          if (genum(11, n10)) equatenum(n10, 18)  .. RANGE
  381.          else decnum(n10)
  382.          equatenum(n[n10], macronum)
  383. >
  384.  
  385. actually I set it to record the last sixteen inputs in my own version -- my
  386. own prekey also has the line equatenum(n32, 0) to make my combined-save-on-
  387. idle-and-rexx-auto-traffic idle key work, and runkey(virtual-=) to make my
  388. word abbrev mode work.
  389.  
  390. Display recent inputs, except normal-mouseclicks
  391. <alt-q: freebuf(buf52)
  392.         insertrgn(buf52, efile, "1 2 3 4 5 6 7 8 9 0 - = \ ?14? kp0 q w e
  393. r t y u i o p [ ] ?28? kp1 kp2 kp3 a s d f g h j k l ; ' ?43? ?44? kp4
  394. kp5 kp6 ?48? z x c v b n m , . / ?59? kpDot kp7 kp8 kp9 space bs tab
  395. kpEnter return esc del menuDown menuUp middleDown kpMinus middleUp upArrow
  396. downArrow rightArrow leftArrow f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 kpLParen
  397. kpRParen kpSlash kpStar kpPlus help buttonDown buttonUp gadget1 gadget2
  398. gadget3 gadget4 closebox ` ?104? ", all)
  399.         movecursor(buf52, sfile)
  400.         while (movecursor(buf52, echar))
  401.             if (is(buf52, space)) swapchar(buf52, eline)
  402.         freebuf(buf51)
  403.         insertrgn(buf51, efile, "0 normal shft alt shftAlt ctl shftCtl
  404. altCtl shftAltCtl lAmiga rAmiga virtual", all)
  405.         freebuf(buf54)
  406.         insertrgn(buf54, efile, "===== Your last eight inputs, newest first:
  407. ", all)
  408.         do (n53, 0, 7) {            .. <<< RANGE  ^^^
  409.             div(n54, n[n10], 104)
  410.             movecursor(buf51, sfile)
  411.             do (n52, 0, n54) movecursor(buf51, eword)
  412.             movecursor(buf51, echar)
  413.             insertrgn(buf54, atcursor, buf51, word)
  414.             insertchar(buf54, "-")
  415.             mod(n54, n[n10], 104)
  416.             linetoloc(buf52, atcursor, n54)
  417.             insertrgn(buf54, efile, buf52, line)
  418.             insertchar(buf54, eline)
  419.             if (genum(n10, 18)) equatenum(n10, 11)  .. RANGE
  420.             else incnum(n10)
  421.         }
  422.         equatenum(n53, curfile)
  423.         editbuf(buf54)
  424.         putmsg("press any key")
  425.         getkey(n54)
  426.         putmsg(" ")
  427.         editbuf(buf[n53])
  428.         freebuf(buf54)
  429.         freebuf(buf52)
  430.         freebuf(buf51)
  431. >
  432.  
  433. Find next usage of an n-variable
  434. <alt-.: getsearch(buf54)
  435.         setsearch("n")
  436.         while (search(curfile, sinvert, einvert, 1)) {
  437.                 equateloc(curfile, atcursor, einvert)
  438.                 if (is(curfile, digit)) goto label (2)
  439.                 if (is(curfile, "[")) goto label (2)
  440.         }
  441.         putmsg("Search failed")
  442.         label (2)
  443.         setsearch(buf54)
  444. >   Well, I had a use for it once...  would work better with grep I guess
  445.  
  446. Report size of file in chars and lines, and current position
  447. <ctl-1: loctoindex(curfile, n54, atcursor)
  448.         sub(n54, n54, 1)
  449.         freebuf(buf54)
  450.         insertrgn(buf54, efile, "Char ", all)
  451.         toword(buf54, n54)
  452.         insertrgn(buf54, efile, " of ", all)
  453.         filesize(curfile, n53)
  454.         toword(buf54, n53)
  455.         insertrgn(buf54, efile, " = ", all)
  456.         mul(n54, n54, 100)
  457.         div(n54, n54, n53)
  458.         toword(buf54, n54)
  459.         insertrgn(buf54, efile, "%    line ", all)
  460.         loctoline(curfile, n54, atcursor)
  461.         toword(buf54, n54)
  462.         insertrgn(buf54, efile, " of ", all)
  463.         loctoline(curfile, n54, efile)
  464.         toword(buf54, n54)
  465.         putmsg(buf54)
  466. > replaces ctl-1 in config!m
  467.  
  468. Save this file with an icon, future file saves without
  469. <lamiga-f2:     if (not getflag(curfile, icons)) flipflag(curfile, icons)
  470.                 savefile(curfile)
  471.                 delay(10)                       .. not infinitely reliable
  472.                 flipflag(curfile, icons)
  473. >
  474.